import request from "@/utils/request";
import {UserForm, UserQuery} from "./model";

class UserAPI {
    /**
     * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
     */
    static getInfo() {
        return request<any, ApiResult>({
            url: "/api/auth/getInfo",
            method: "post",
        });
    }


    /**
     * 获取用户分页列表
     *
     * @param queryParams
     */
    static getPage(queryParams: UserQuery) {
        return request<any, ApiResult>({
            url: "/api/user/listPage",
            method: "post",
            data: queryParams,
        });
    }


    /**
     * 添加用户
     *
     * @param data
     */
    static add(data: UserForm) {
        return request({
            url: "/api/user/add",
            method: "post",
            data: data,
        });
    }

    /**
     * 修改用户
     *
     * @param id
     * @param data
     */
    static update(data: UserForm) {
        // this.deleteTimeField(data)
        return request({
            url: "/api/user/update",
            method: "post",
            data: data,
        });
    }
    static updateSelfInfo(data: any) {
        return request({
            url: "/api/user/updateSelfInfo",
            method: "post",
            data: data,
        });
    }
    static updateSelfPassword(data: any) {
        return request({
            url: "/api/user/updateSelfPassword",
            method: "post",
            data: data,
        });
    }

    /**
     * 修改用户密码
     *
     * @param id
     * @param password
     */
    static updatePassword(id: number, password: string) {
        return request({
            url: "/api/user/updatePassword",
            method: "post",
            data: {newPassword: password, userId: id},
        });
    }

    /**
     * 删除用户
     *
     * @param ids
     */
    static deleteByIds(ids: string) {
        return request({
            url: "/api/user/delete",
            method: "post",
            data: {idsStr: ids},
        });
    }

    /**
     * 下载用户导入模板
     *
     * @returns
     */
    static downloadTemplate() {
        return request({
            url: "/api/user/template",
            method: "post",
            responseType: "arraybuffer",
        });
    }


    static unlockUser(username: string ) {
        return request({
            url: "/api/user/unlockUser",
            method: "post",
            data: {username: username},
        });
    }

    static kickOffline(username: string) {
        return request({
            url: "/api/auth/offlineUser",
            method: "post",
            data: {username: username},
        });
    }
}

export default UserAPI;
